<template>
	<view class="page">
		<uni-section type="line" title="查询条件">
			<view class="form">
				<uni-forms label-position="top" label-width="120">
					<uni-forms-item label="设备状态" name="machineStatus">
						<uni-data-picker placeholder="请选择设备状态" popup-title="请选择订单状态" :localdata="machineStateList" v-model="machineStatus" />
					</uni-forms-item>
					<uni-forms-item label="缺货率" name="outStockRate">
						<view class="flex-row-start">
							<view class="margin-lr-10">缺货率大于</view>
							<uni-number-box v-model="outStockRate"></uni-number-box>
							<view class="margin-lr-10">%</view>
						</view>
					</uni-forms-item>
				</uni-forms>
			</view>
		</uni-section>
		<view class="form-btn">
			<button type="warn" @click="reset">重置</button>
			<button type="primary" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				machineStateList: [
					{ value: 0, text: "全部" },
					{ value: 1, text: "正常" },
					{ value: 2, text: "故障" }
				],
				machineStatus: "",
				outStockRate: "",
			}
		},
		
		onShow() {
			let search = uni.getStorageSync('searchStock')
			if(search) {
				let searchData = JSON.parse(search)
				
				this.machineStatus = searchData.machineStatus
				this.outStockRate = searchData.outStockRate
			}
		},
		
		methods: {
			reset() {
				this.machineStatus= ''
				this.outStockRate= ''
				this.submit()
			},
			
			submit() {
				let data = {
					machineStatus: this.machineStatus,
					outStockRate: this.outStockRate
				}
				
				uni.setStorageSync('searchStock', JSON.stringify(data))
				
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100vh;
		background-color: #fff;
	}
	
 .form {
	 padding: 20rpx;
 }
 
 .form-btn {
	 width: 100%;
	 box-sizing: border-box;
	 position: absolute;
	 bottom: 80rpx;
	 padding: 10rpx;
	 display: flex;
	 align-items: center;
		
		button {
			width: 320rpx;
		}
 }
</style>